package com.sample;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;




import java.lang.reflect.Field;

import org.junit.Test;

 
public class HeartTest {
	 private static final double DELTA = 1e-15; 

	 @Test
		public void test1() {
		 Heart testObj = new Heart(){
			public double teststub()
			{
				return 20;
			}
		 };
		 double  act = testObj.testfun();
		 double exp = 22;
		 assertEquals(exp, act, DELTA);
	 }
	 
	@Test
	public void test() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
		//fail("Not yet implemented");  
		Circle mockedCircle = mock(Circle.class);  		 
		when(mockedCircle.calcArea()).thenReturn(Math.PI);
		mockedCircle.R = 20;
		
		Triangle mockedTriangle = mock(Triangle.class);  
		when(mockedTriangle.calcArea()).thenReturn(8.0);
		
	 	Heart testObj = new Heart();
	 	testObj.down = mockedTriangle;
	 	
		Field field = Heart.class.getDeclaredField("up");
		field.setAccessible(true);
		System.out.println(field.getType());
		Circle temp = (Circle)field.get(testObj);
		System.out.println(temp.R);
		
	 	field.set(testObj, mockedCircle);    
	 	System.out.println(((Circle)field.get(testObj)).R);
	 	
//		testObj.up = mockedCircle;
//		testObj.up.R = 1;
//		testObj.down.B = 4;
//		testObj.down.H = 4; 
	 	
		double act = testObj.calcArea(); 
		assertEquals(8 + Math.PI, act, DELTA); 
	}

}
